<template>
	<view style="overflow: hidden;">
		<view class="uni-container" style="float: left;">
			<span>大转盘设置(每格为奖励现金数,概率为千分比且必须整数)</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="格子1" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role1" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率1" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv1" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子2" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role2" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率2" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv2" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子3" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role3" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率3" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv3" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子4" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role4" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率4" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv4" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子5" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role5" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率5" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv5" style="width: 200px;" />
				</uni-forms-item>


				<uni-forms-item label="格子6" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role6" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率6" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv6" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子7" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role7" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率7" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv7" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="格子8" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role8" style="width: 200px;" />
				</uni-forms-item>

				<uni-forms-item label="概率8" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.gailv8" style="width: 200px;" />
				</uni-forms-item>

				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading"
						@click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading: false,
				"roles": {
					"role1": 0,
					"role2": 0,
					"role3": 0,
					"role4": 0,
					"role5": 0,
					"role6": 0,
					"role7": 0,
					"role8": 0,
					"gailv1": 0, //千分比
					"gailv2": 0, //千分比
					"gailv3": 0, //千分比
					"gailv4": 0, //千分比
					"gailv5": 0, //千分比
					"gailv6": 0, //千分比
					"gailv7": 0, //千分比
					"gailv8": 0 //千分比
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo() {
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'roles'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.roles = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save() {
				this.isLoading = true
				delete this.roles._id;
				for (let key in this.roles) {
					if (key != '_id') {
						this.roles[key] = Number(this.roles[key])
					}
				}
				console.log(this.roles)
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/changeroles",
						data: {
							json: JSON.stringify(this.roles)
						}
					}
				}).then((res) => {
					console.log(res, "save-------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
				// this.$request('admin/changeroles', {json: JSON.stringify(this.roles)}).then(res => {
				// 	this.isLoading = false
				// 	uni.showToast({
				// 		title: "修改成功",
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// }).catch(res => {

				// }).finally(err => {
				// 	this.isLoading = false
				// })
			}
		}
	}
</script>

<style>

</style>
